home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Helpers / Tzu Release 4 / Tool Development / Wrap.cp < prev    next >
Encoding:
Text File  |  1994-10-15  |  909 b   |  50 lines  |  [TEXT/MMCC]

  1. // *
  2. // * Wrap Tzu
  3. // * ©1994 Chris K. Thomas.  All Rights Reserved.
  4. // * 
  5. // * 100 15 Oct 94 ckt - new efficientized wrap
  6.  
  7. #include "TzuTools.h"
  8. #include "TzuTextUtils.h"
  9.  
  10. pascal void main(Handle text);
  11.  
  12. const short leftMargin    = 4;
  13. short rightMargin    = 75;
  14.  
  15. // * Main entry point
  16. // text - handle to text to be modified
  17. pascal void main(Handle text)
  18. {
  19.     EnterCodeResource();
  20.     
  21.     long         sizeOfText    = GetHandleSize(text);
  22.     Ptr            localText    = *text;
  23.     
  24.     for(long i=0; i<(sizeOfText-1); i++)
  25.     {
  26.         // set all whitespace and returns to space character
  27.         if(localText[i] == '\r' || localText[i] == '\t')
  28.         {
  29.             localText[i]=' ';
  30.         }
  31.         
  32.         // if we're on the margin
  33.         if(i % rightMargin == 0)
  34.         {
  35.             // backtrack to find the first space
  36.             // character before the margin
  37.             short k = i+1;
  38.             while(--k)
  39.             {
  40.                 if(localText[k] == ' ')
  41.                 {
  42.                     localText[k] = '\r';
  43.                     break;
  44.                 }
  45.             }
  46.         }
  47.     }
  48.     
  49.     ExitCodeResource();
  50. }